package cate.game.role;

import cate.common.table.ins.InstanceRsRow;
import cate.game.role.base.RoleBase;
import cate.game.role.show.avatar.AvatarVO;
import cate.game.role.show.frame.HeadFrameVO;
import cate.game.role.show.icon.HeadIconVO;
import cate.game.role.show.title.TitleVO;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

@NoteClass(value = "简要的玩家基础数据", detail = "这里只记录别人观察时玩家最基础的数据")
@ToString
public class RoleSimpleBase {

	@NoteField("玩家唯一id")
	public String uid;

	@NoteField("当前游戏服ID")
	public int srvId;

	@NoteField("原始的游戏服ID")
	public int srvIdOrigin;

	@NoteField("角色名")
	public String name;

	@NoteField("角色性别")
	public byte sex;

	@NoteField("角色等级")
	public int level;

	@NoteField("角色VIP等级")
	public int vip;

	@NoteField(value = "角色头像")
	public HeadIconVO headIcon;

	@NoteField("头像框")
	public HeadFrameVO headFrame;

	@NoteField("冒险形象")
	public AvatarVO avatar;

	@NoteField("称号")
	public TitleVO title;

	@NoteField("战力")
	public long power;


	public RoleSimpleBase read(RoleBase roleBase) {
		if (roleBase == null) {
			return this;
		}
		this.uid = roleBase.uid;
		this.srvId = roleBase.srvId;
		this.srvIdOrigin = roleBase.srvIdOrigin;
		this.name = roleBase.name;
		this.sex = roleBase.sex;
		this.level = roleBase.level;
		this.vip = roleBase.vip;
		this.headIcon = roleBase.headIcon != null ? roleBase.headIcon.copy() : null;
		this.headFrame = roleBase.headFrame != null ? roleBase.headFrame.copy() : null;
		this.avatar = roleBase.avatar != null ? roleBase.avatar.copy() : null;
		this.title = roleBase.title != null ? roleBase.title.copy() : null;
		this.power = roleBase.power;
		return this;
	}

	public void readByInstanceRow(InstanceRsRow row){
		this.level = row.level;
		this.name = row.name;
		this.sex = row.gender;
		this.headIcon = new HeadIconVO(row.headIcon);
		this.headFrame = new HeadFrameVO(row.headFrame);
		this.avatar = new AvatarVO(row.avatarId);
	}

	public RoleSimpleBase copy(){
		RoleSimpleBase cp = new RoleSimpleBase();
		cp.uid = this.uid;
		cp.srvId = this.srvId;
		cp.srvIdOrigin = this.srvIdOrigin;
		cp.name = this.name;
		cp.sex = this.sex;
		cp.level = this.level;
		cp.vip = this.vip;
		cp.headIcon = this.headIcon!=null?headIcon.copy():null;
		cp.headFrame = this.headFrame!=null?headFrame.copy():null;
		cp.avatar = this.avatar!=null?avatar.copy():null;
		cp.title = this.title!=null?title.copy():null;
		cp.power = this.power;
		return cp;
	}

	@JsonIgnore
	public boolean isEmpty(){
		return StringUtils.isEmpty(uid);
	}
}
